<template>
  <h1>{{ num }}</h1>
  <button @click="num++">点击+1</button>
  <h1>{{ y.x }}</h1>
  <button @click="y={x:999}">点击替换y</button>
  <h1>{{ person }}</h1>
  <h1>姓名：{{ name }}</h1>
  <h1>年龄：{{ age }}</h1>
  <h1>薪资：{{ salary }}K</h1>
  <button @click="name += '~'">修改姓名</button>
  <br />
  <button @click="age++">增长年龄</button>
  <br />
  <button @click="person.job.j1.salary++">涨薪</button>
</template>

<script>
// 体现出了组合式API的使用
import { reactive, shallowRef,toRefs} from "vue";
export default {
  name: "myDemo",
  setup() {
    // let person = shallowReactive({})
    let num = shallowRef(0);
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        j1: {
          salary: 10,
        },
      },
    });

    let y = shallowRef({
       x:0
    })

    // (3)toRef可以拿到某个对象的引用来响应式更新对应属性
    return {
      num,
      y,
      person,
      ...toRefs(person),
    };
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped></style>
